define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'area/index' + location.search,
                    add_url: 'area/add',
                    edit_url: 'area/edit',
                    del_url: 'area/del',
                    // multi_url: 'area/multi',
                    import_url: 'area/import',
                    table: 'area',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shortname', title: __('Shortname'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        // {field: 'mergename', title: __('Mergename'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'level', title: __('Level'), searchList: {"1":__('Level 1'),"2":__('Level 2'),"3":__('Level 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'pinyin', title: __('Pinyin'), operate: false},
                        // {field: 'code', title: __('Code'), operate: 'LIKE'},
                        // {field: 'zip', title: __('Zip'), operate: 'LIKE'},
                        {field: 'first', title: __('First'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                search:false,
                searchFormVisible: true,
                
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        indexcity: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'area/indexCity' + location.search,
                    add_url: 'area/addCity',
                    edit_url: 'area/editCity',
                    del_url: 'area/delCity',
                    // multi_url: 'area/multi',
                    // import_url: 'area/import',
                    table: 'area',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shortname', title: __('Shortname'), operate: false},
                        {field: 'name', title: __('Name'), operate: false},
                        {field: 'parea.name', title: __('所属省份'), operate: false},
                        {field: 'area_code', title: __('城市代码'), operate: false},
                        {field: 'is_hot', title: __('热门城市'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.normal},
                        // {field: 'mergename', title: __('Mergename'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'level', title: __('Level'), searchList: {"1":__('Level 1'),"2":__('Level 2'),"3":__('Level 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'pinyin', title: __('Pinyin'), operate: false},
                        // {field: 'code', title: __('Code'), operate: 'LIKE'},
                        // {field: 'zip', title: __('Zip'), operate: 'LIKE'},
                        {field: 'first', title: __('First'), operate: false},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormTemplate: 'customformtpl',
                search:false,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        addcity: function () {
            Controller.api.bindevent();
        },
        editcity: function () {
            Controller.api.bindevent();
        },
        indexcityair: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'area/indexCityAir' + location.search,
                    add_url: 'area/addCityAir',
                    edit_url: 'area/editCityAir',
                    del_url: 'area/delCityAir',
                    // multi_url: 'area/multi',
                    // import_url: 'area/import',
                    table: 'area',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'shortname', title: __('机场简称'), operate: 'LIKE'},
                        {field: 'name', title: __('机场全称'), operate: 'LIKE'},
                        {field: 'parea.name', title: __('所属城市'), operate: false},
                        {field: 'airport_3', title: __('三字码'), operate: 'LIKE'},
                        {field: 'airport_4', title: __('四字码'), operate: 'LIKE'},
                        // {field: 'mergename', title: __('Mergename'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'level', title: __('Level'), searchList: {"1":__('Level 1'),"2":__('Level 2'),"3":__('Level 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'pinyin', title: __('Pinyin'), operate: false},
                        // {field: 'code', title: __('Code'), operate: 'LIKE'},
                        // {field: 'zip', title: __('Zip'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormTemplate: 'customformtpl',
                search:false,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        addcityair: function () {
            Controller.api.bindevent();
        },
        editcityair: function () {
            Controller.api.bindevent();
        },
        indexcountry: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'area/indexCountry' + location.search,
                    add_url: 'area/addCountry',
                    edit_url: 'area/editCountry',
                    del_url: 'area/delCountry',
                    // multi_url: 'area/multi',
                    // import_url: 'area/import',
                    table: 'area',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'shortname', title: __('Shortname'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'parea.name', title: __('所属区域'), operate: false},
                        // {field: 'mergename', title: __('Mergename'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'level', title: __('Level'), searchList: {"1":__('Level 1'),"2":__('Level 2'),"3":__('Level 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'pinyin', title: __('Pinyin'), operate: false},
                        // {field: 'code', title: __('Code'), operate: 'LIKE'},
                        // {field: 'zip', title: __('Zip'), operate: 'LIKE'},
                        // {field: 'first', title: __('First'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                search:false,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        addcountry: function () {
            Controller.api.bindevent();
        },
        editcountry: function () {
            Controller.api.bindevent();
        },
        indexcountrycity: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'area/indexCountryCity' + location.search,
                    add_url: 'area/addCountryCity',
                    edit_url: 'area/editCountryCity',
                    del_url: 'area/del',
                    // multi_url: 'area/multi',
                    // import_url: 'area/import',
                    table: 'area',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'shortname', title: __('Shortname'), operate: 'LIKE'},
                        {field: 'name', title: __('Name'), operate: 'LIKE'},
                        {field: 'parea.name', title: __('所属国家'), operate: false},
                        {field: 'area_code', title: __('城市代码'), operate: 'LIKE'},
                        {field: 'is_hot', title: __('热门城市'), searchList: {"0":__('否'),"1":__('是')}, formatter: Table.api.formatter.normal},
                        // {field: 'mergename', title: __('Mergename'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        // {field: 'level', title: __('Level'), searchList: {"1":__('Level 1'),"2":__('Level 2'),"3":__('Level 3')}, formatter: Table.api.formatter.normal},
                        // {field: 'pinyin', title: __('Pinyin'), operate: false},
                        // {field: 'code', title: __('Code'), operate: 'LIKE'},
                        // {field: 'zip', title: __('Zip'), operate: 'LIKE'},
                        {field: 'first', title: __('First'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormTemplate: 'customformtpl',
                search:false,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        addcountrycity: function () {
            Controller.api.bindevent();
        },
        editcountrycity: function () {
            Controller.api.bindevent();
        },
        indexccityair: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'area/indexCcityAir' + location.search,
                    add_url: 'area/addCcityAir',
                    edit_url: 'area/editCcityAir',
                    del_url: 'area/del',
                    // multi_url: 'area/multi',
                    // import_url: 'area/import',
                    table: 'area',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        // {field: 'shortname', title: __('Shortname'), operate: 'LIKE'},
                        {field: 'shortname', title: __('机场简称'), operate: 'LIKE'},
                        {field: 'name', title: __('机场全称'), operate: 'LIKE'},
                        {field: 'parea.name', title: __('所属国家'), operate: false},
                        {field: 'airport_3', title: __('三字码'), operate: 'LIKE'},
                        {field: 'airport_4', title: __('四字码'), operate: 'LIKE'},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ],
                showToggle: false,
                showColumns: false,
                showExport: false,
                searchFormTemplate: 'customformtpl',
                search:false,
                searchFormVisible: true,
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        addccityair: function () {
            Controller.api.bindevent();
        },
        editccityair: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
